package com.cwnu.service.impl;

import com.cwnu.entity.Comment;
import com.cwnu.entity.User;
import com.cwnu.mapper.CommentMapper;
import com.cwnu.service.CommentService;
import com.cwnu.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public void deleteComment(Integer id) {
        commentMapper.deleteComment(id);
    }

    @Override
    public void createComment(Integer articleId, String content) {
        // 获取当前用户id
        Integer createId = TokenUtil.getUserId();
        commentMapper.createComment(articleId, content, createId);
    }

    @Override
    public List<Comment> getCommentsByArticleId(Integer articleId) {
        return commentMapper.getCommentsByArticleId(articleId);
    }

    @Override
    public User getUserByUserId(Integer id) {
        return commentMapper.getUserByUserId(id);
    }
}
